import { IRemarkModel } from '../model/record/remark'
import * as remarkRepo from '../repository/remark'
import { Md5 } from 'ts-md5'

export const createRemark = async (payload: IRemarkModel): Promise<IRemarkModel> => {
  if (!payload.content || payload.content.length <= 0) {
    global.UnifyResponse.error({ code: -1, message: '模板内容不能为空' })

  }
  return remarkRepo.create(payload)
}
export const bulkBuildRemark = async (payload: [IRemarkModel]): Promise<IRemarkModel[]> => {
    if (payload.length <= 0) {
      global.UnifyResponse.error({ code: -1, message: '评价不能为空' })
    }
    return remarkRepo.bulkBuild(payload)
  }
export const updateRemark = async (
  id: number,
  payload: {}
): Promise<[affectedCount: number]> => {
  return remarkRepo.update(id, payload)
}

export const getRemarkById = (id: number): Promise<IRemarkModel> => {
  return remarkRepo.getById(id)
}

export const findRemark = (payload: IRemarkModel): Promise<IRemarkModel> => {
  if (!payload.content || payload.content.length <= 0) {
    global.UnifyResponse.error({ code: -1, message: '模板内容不能为空' })

  }
  return remarkRepo.findRemark(payload)
}
export const getRemarkByMould = (id: number): Promise<IRemarkModel[]> => {
  return remarkRepo.getByMould(id)
}
export const deleteById = (id: number): Promise<boolean> => {
  let result = remarkRepo.deleteById(id)
  if (!result) {
    global.UnifyResponse.error({ code: -1, message: '删除失败' })
  }
  return result
}

export const getAll = (): Promise<IRemarkModel[]> => {
  return remarkRepo.getAll()
}
